public class Main {
    public static void main(String[] args) {
        int[] arr = {0,0,1,1,1,2,2,3,3,4};
        int p=0,q=1;
        while(q<arr.length){
            if(arr[p]!=arr[q]){
                arr[p+1]=arr[q];
                p++;
            }
            q++;
        }
        System.out.println(p+1);//去重后元素个数
        for(int i=0;i<p+1;i++){
            System.out.print(arr[i]+" ");//去重后输出数组
        }
    }
}
